var t = getApp();

Page({
    data: {
        activityId: "",
        baseUrl: t.globalData.baseUrl,
        distance: "",
        lat: "",
        lng: "",
        address: "",
        activity: [ {
            baseSell: "",
            createTime: "",
            id: "",
            img: "",
            imgs: "",
            imgsList: [],
            name: "",
            num: "",
            oldPrice: "",
            other: "",
            price: "",
            reamrk: "",
            sellCount: "",
            serverFlow: "",
            serverTIME: "",
            service: "",
            storeId: "",
            useTime: "",
            userfulPeople: "",
            userfulTime: ""
        } ],
        serverList: [ {
            code: "",
            createTime: "",
            gift: "",
            id: "",
            img: "",
            imgs: "",
            isRecommend: "",
            name: "",
            phone: "",
            remark: "",
            serverCount: "",
            sortOrder: "",
            storeId: ""
        } ],
        imgUrls: [ "../../pic/prodetail.jpg" ],
        currentTab: 0
    },
    onLoad: function(a) {
        var e = this, r = t.globalData.urlBase + t.globalData.urlactivitydetailList;
        a.type;
        e.setData({
            activityId: a.id ? a.id : "",
            orderId: a.orderid ? a.orderid : "",
            type: a.type,
            ctshare: a.ctshare
        }), t.globalData.ctData.activityId = a.id, t.globalData.ctData.actType = 1, t.globalData.ctData.orderId = a.orderid, 
        t.globalData.ctData.ctshare = 1, wx.getStorageSync("userId") || t.goLogin(), console.log("activityId" + a.id + "type:" + a.type + "lng: " + t.globalData.lng + "lat" + t.globalData.lat), 
        "" == t.globalData.lng || "" == t.globalData.lng ? wx.getLocation({
            type: "wgs84",
            success: function(a) {
                var i = a.latitude, o = a.longitude;
                t.globalData.lat = i, t.globalData.lng = o, e.getdata(r);
            }
        }) : e.getdata(r);
    },
    getdata: function(a) {
        var e = this;
        wx.request({
            url: a,
            data: {
                activityId: e.data.activityId,
                type: e.data.type,
                lng: t.globalData.lng,
                lat: t.globalData.lat,
                orderId: e.data.orderId
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                console.log(a);
                var r = JSON.parse(a.data);
                JSON.parse(a.data).activity;
                var i = [];
                i = r.activity.imgs.split(","), r.activity.imgsList = [];
                for (var o = 0; o < i.length; o++) r.activity.imgsList.push(t.globalData.baseUrl + "download/" + i[o]);
                e.setData({
                    serverList: r.serverList,
                    store: r.store,
                    activity: r.activity,
                    type: e.data.type,
                    lat: r.store.lat,
                    lng: r.store.lng,
                    name: r.store.name,
                    address: r.store.address,
                    shareName: r.activity.name ? r.activity.name : "",
                    shareImg: r.activity.imgsList[0] ? r.activity.imgsList[0] : ""
                });
            },
            fail: function(t) {
                console.log(".....fail.....");
            }
        });
    },
    bindChange: function(t) {
        this.setData({
            currentTab: t.detail.current
        });
    },
    openMap: function() {
        var t = this;
        wx.openLocation({
            latitude: parseFloat(t.data.lat),
            longitude: parseFloat(t.data.lng),
            name: t.data.name,
            address: t.data.address
        });
    },
    swichNav: function(t) {
        var a = this;
        if (this.data.currentTab === t.target.dataset.current) return !1;
        a.setData({
            currentTab: t.target.dataset.current
        });
    },
    groupaction: function(t) {
        var a = this;
        wx.navigateTo({
            url: "../activity/detail?id=" + t.currentTarget.dataset.id + "&type=" + t.currentTarget.dataset.type + "&orderid=" + a.data.orderId
        });
    },
    groupicon: function(t) {
        wx.navigateTo({
            url: "../index/detail?id=" + t.currentTarget.dataset.id + "&type=" + t.currentTarget.dataset.type
        });
    },
    onShareAppMessage: function(t) {
        var a = this;
        return "button" === t.from ? (console.log("来自页面内转发按钮"), console.log(t.target)) : console.log("来自右上角转发菜单"), 
        {
            title: a.data.shareName,
            imageUrl: a.data.shareImg,
            success: function(t) {
                console.log("转发成功", t);
            },
            fail: function(t) {
                console.log("转发失败", t);
            }
        };
    }
});